/* Copyright 203-2115 AtomWare Technology Pty Limited
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 * The flowing information must be keep 
 * RemindEvent.java
 * netty-socket-io
 * 2013年9月16日上午9:30:58
 * @author 屈甲康
 * QQ285799123
 * mailto:qujiakang@gmail.com
 */

package org.jackysoft.entity.nosql;

import java.util.Map;

import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.jackysoft.nosql.RemindEventType;
import org.joda.time.DateTime;
import org.mongodb.morphia.annotations.Embedded;

import com.google.common.collect.Maps;

public class RemindEvent extends AbstractNetMessage {

	/**
	 * 
	 */
	private static final long serialVersionUID = -6481038482263298835L;
	protected int eventType = 0;
	protected long firetime;
	protected @Embedded NameValuePair sender;
	protected String receiver;
	protected long lastNotificed = 0;
	protected boolean valid;
	protected static Map<Integer, String> patterns;
	protected long datetime;
	protected String extraProp;
	static {		
		patterns = Maps.newHashMap();
		StringBuilder sb = new StringBuilder();
		sb.append("<span class='label label-info'>%s</span>于%s传来公文<span class='label label-inverse'>%s</span>,<span class='label label-info'>%s</span>,请登录OA及时办理");
		patterns.put(RemindEventType.PROCESS, sb.toString());
		sb = new StringBuilder();
		sb.append("<span class='label label-info'>%s</span>于%s 发来文件 <span class='label label-info'>%s</span>");
		sb.append("<button type=\"button\" class='btn btn-mini btn-info' onclick=\"downfile('%s',event)\"><i class='icon-download-alt'></i></button>");
		patterns.put(RemindEventType.FILE, sb.toString());
		patterns.put(RemindEventType.IMFILE, sb.toString());
	}

	public RemindEvent() {
		this.datetime = DateTime.now().getMillis();
	}

	/**
	 * <ul>
	 * <li>0 收到文件</li>
	 * <li>1 收到待办事项</li>
	 * <li>2 紧急提示</li>
	 * </ul>
	 * 
	 * */
	public int getEventType() {
		return eventType;
	}

	public long getFiretime() {
		return firetime;
	}

	public String getReceiver() {
		return receiver;
	}

	public void setEventType(int eventType) {
		this.eventType = eventType;
	}

	public void setFiretime(long firetime) {
		this.firetime = firetime;
	}

	public void setReceiver(String receiver) {
		this.receiver = receiver;
	}

	public boolean isValid() {
		return valid;
	}

	public void setValid(boolean valid) {
		this.valid = valid;
	}

	@Override
	public String toString() {
		return ToStringBuilder.reflectionToString(this,
				ToStringStyle.SIMPLE_STYLE);
	}

	public long getLastNotificed() {
		return lastNotificed;
	}

	public void setLastNotificed(long lastNotificed) {
		this.lastNotificed = lastNotificed;
	}

	@Override
	public String getContent() {
		return String.format(patterns.get(getEventType()), args);
	}

	public long getDatetime() {
		return datetime;
	}

	public void setDatetime(long datetime) {
		this.datetime = datetime;
	}

	public NameValuePair getSender() {
		return sender;
	}

	public void setSender(NameValuePair sender) {
		this.sender = sender;
	}
	
	
	public String getSenderId(){return sender.getName();}
	public String getSenderName(){return sender.getValue();}

	public String getExtraProp() {
		return extraProp;
	}

	public void setExtraProp(String extraProp) {
		this.extraProp = extraProp;
	}

}
